import $ from "jquery";
import {url} from "../../util/config";
import {error as exception, success} from "../../util/responseStatus";
import {message} from "antd";
import login from "../login";
function getNewLogin(values) {
    return moveData(values)
}
export default function moveData(values){

    let token = localStorage.getItem("token")

    let status = null;

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`move/moveModuleAndFile`,
        type: 'POST',
        data:JSON.stringify(values),
        // data:{
        //     ID:values.ID,
        //     TYPE:values.TYPE,
        //     NEW_PARENT_ID:values.NEW_PARENT_ID,		//新的父节点Id
        //     NEW_PARENT_TYPE: values.NEW_PARENT_TYPE,
        //     NEW_LAYOUT_AREA:values.NEW_LAYOUT_AREA
        // },
        contentType:"application/json",
        success: function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(values)
            }else {
                if(result.result=="ok"){
                    message.success("提交成功!")
                    status = "ok"
                }else if(result.result=="conflict"){
                    message.error(`命名冲突 ! 该节点下已存在同名节点`)
                    status = "error"
                }else {
                    message.error(result.result)
                    status = "error"
                }
            }
        },
        error:function (error) {
            status = "error"
            message.error("请求异常")
        }
    })
    return status;
    // return "ok"
}
